package com.eshin.configuration.beanprocessor;

import com.eshin.autotest.controller.HelloController;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author Eshin
 * @title: CustomBeanFactoryPostProcessor
 * @projectName pay
 * @date 2019/6/1717:27
 */

/**
 * 对bean实例的前置后置处理
 */
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.contains("hello")){
            if(beanName.equals("helloController")){
                HelloController heCo = (HelloController) bean;
                heCo.hello.add("hello eshin");
                heCo.hello.add("hello world");
            }
            System.out.println(beanName+" proccessed by CustomBeanPostProcessor.postProcessBeforeInitialization");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.contains("hello")){
            System.out.println(beanName+" proccessed by CustomBeanPostProcessor.postProcessAfterInitialization");
        }
        return bean;
    }
}
